namespace e5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            GetRootDirectoryInfo();
        }

        private void GetRootDirectoryInfo()
        {
            foreach (string dirname in Directory.GetLogicalDrives())
            {
                DirectoryInfo dir = new DirectoryInfo(dirname);
                TreeNode node = new TreeNode(dirname);
                node.ToolTipText = dir.FullName;
                treeView1.Nodes.Add(node);
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {


            e.Node.Nodes.Clear();
            DirectoryInfo dir = new DirectoryInfo(e.Node.ToolTipText);
            Get_SubDirectory_Info(dir, e.Node);

            listView1.Items.Clear();
            foreach (FileInfo file in dir.GetFiles())
            {
                ListViewItem item = new ListViewItem(file.Name);
                item.SubItems.Add(file.Length.ToString());
                item.SubItems.Add(file.LastWriteTime.ToString());
                listView1.Items.Add(item);
            }
        }
        private void Get_SubDirectory_Info(DirectoryInfo dir, TreeNode node)
        {
            try
            {
                foreach (DirectoryInfo sub_dir in dir.GetDirectories())
                {
                    TreeNode sub_node = new TreeNode(sub_dir.Name);
                    sub_node.ToolTipText = sub_dir.FullName;
                    node.Nodes.Add(sub_node);


                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
    }

}